﻿using DXApplicationTangche.UC.抖音出入库.Service;
using DXApplicationTangche.UC.抖音出入库.抖音UC;
using DXApplicationTangche.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.抖音出入库
{
    public partial class Form抖音金蝶单据查询 : DevExpress.XtraEditors.XtraForm
    {
        private XtraUserControl销售收款 xtraUserControl收款单 = new XtraUserControl销售收款();
        private XtraUserControl收款退款明细 xtraUserControl销售退款 = new XtraUserControl收款退款明细();
        private XtraUserControl收款退款明细 xtraUserControl退款退货 = new XtraUserControl收款退款明细();
        private XtraUserControl收款退款明细 xtraUserControl退款未退货 = new XtraUserControl收款退款明细();
        private XtraUserControl抖音发货对账 xtraUserControl抖音发货出库对账 = new XtraUserControl抖音发货对账();

        public Form抖音金蝶单据查询()
        {
            InitializeComponent();
        }

        private void dateTimePicker开始时间_CloseUp(object sender, EventArgs e)
        {
            //this.刷新(this.dateTimePicker开始时间.Value.ToString("yyyy-MM-dd"));
        }
        private void 刷新(String dataStr)
        {
            this.splashScreenManager.ShowWaitForm();
            this.splashScreenManager.SetWaitFormCaption("请稍后,正在加载中....");     // 标题
            this.splashScreenManager.SetWaitFormDescription("正在初始化.....");
            //查询收款单
            DouyinFinancialQueryFacadeDTO douyinFinancialQueryFacade收款单 = 抖音订单Service.getDouyinFinancialSimple("销售收款", dataStr);
            this.xtraUserControl收款单 = new XtraUserControl销售收款(douyinFinancialQueryFacade收款单);
            this.xtraUserControl收款单.Dock = DockStyle.Fill;
            this.panel销售收款.Controls.Clear();
            this.panel销售收款.Controls.Add(this.xtraUserControl收款单);
            //查询销售退款单
            DouyinFinancialQueryFacadeDTO douyinFinancialQueryFacade销售退款 = 抖音订单Service.getDouyinFinancialSimple("销售退款", dataStr);
            this.xtraUserControl销售退款 = new XtraUserControl收款退款明细(douyinFinancialQueryFacade销售退款);
            this.xtraUserControl销售退款.Dock = DockStyle.Fill;
            this.panel销售退款.Controls.Clear();
            this.panel销售退款.Controls.Add(this.xtraUserControl销售退款);
            //查询退款退货
            DouyinFinancialQueryFacadeDTO douyinFinancialQueryFacade退款退货 = 抖音订单Service.getDouyinFinancialSimple("退款退货", dataStr);
            this.xtraUserControl退款退货 = new XtraUserControl收款退款明细(douyinFinancialQueryFacade退款退货);
            this.xtraUserControl退款退货.Dock = DockStyle.Fill;
            this.panel退款退货.Controls.Clear();
            this.panel退款退货.Controls.Add(this.xtraUserControl退款退货);
            //查询退款未退货
            DouyinFinancialQueryFacadeDTO douyinFinancialQueryFacade退款未退货 = 抖音订单Service.getDouyinFinancialSimple("退款未退货", dataStr);
            this.xtraUserControl退款未退货 = new XtraUserControl收款退款明细(douyinFinancialQueryFacade退款未退货);
            this.xtraUserControl退款未退货.Dock = DockStyle.Fill;
            this.panel退款未退货.Controls.Clear();
            this.panel退款未退货.Controls.Add(this.xtraUserControl退款未退货);
            //查询抖音发货出库对账
            List<DouyinStockOutCheckDTO> douyinOrderStockOut抖音发货出库对账 = 抖音订单Service.getDouyinOrderStockOutByDateStr(dataStr);
            this.xtraUserControl抖音发货出库对账 = new XtraUserControl抖音发货对账(douyinOrderStockOut抖音发货出库对账);
            this.xtraUserControl抖音发货出库对账.Dock = DockStyle.Fill;
            this.panel抖音发货出库对账.Controls.Clear();
            this.panel抖音发货出库对账.Controls.Add(this.xtraUserControl抖音发货出库对账);
            this.splashScreenManager.CloseWaitForm();
        }

        private void simpleButton订单导入_Click(object sender, EventArgs e)
        {
            new Form抖音订单下达收款单().ShowDialog();
        }

        private void simpleButton导出订单_Click(object sender, EventArgs e)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出订单明细";
            fileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                //保存销售收款单、退款退货单、退款未退货单
                this.xtraUserControl收款单.gridView订单明细.ExportToXlsx(Path.GetFullPath(@"tag\" + "收款单.xlsx"));
                this.xtraUserControl销售退款.gridView订单明细.ExportToXlsx(Path.GetFullPath(@"tag\" + "销售退款.xlsx"));
                this.xtraUserControl退款退货.gridView订单明细.ExportToXlsx(Path.GetFullPath(@"tag\" + "退款退货.xlsx"));
                this.xtraUserControl退款未退货.gridView订单明细.ExportToXlsx(Path.GetFullPath(@"tag\" + "退款未退货.xlsx"));
                //合并到一个excel的多个sheet
                ExcelUtil.saveCombineSheet(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("文件已保存至" + fileDialog.FileName, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}
